<template>
	<view class="goodsDetailPage">
		<swiper circular indicator-dots autoplay :interval="3000" :duration="1000">
			<swiper-item v-for="(item,index) in list.rotationChart" :key="index">
				<image :src="item" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="priceName">
			<view class="price">
				<text>￥{{list.sell_price}}</text>
				<text>￥{{list.market_price}}</text>
			</view>
			<view class="name">{{list.title}}</view>
		</view>

		<!-- 灰色的背景线 -->
		<view class="line"></view>

		<!-- 货号和库存 -->
		<view class="goodsNumberStock">
			<view>货号 : {{list.goodsNumber}}</view>
			<view>库存 : {{list.stock}}</view>
		</view>

		<!-- 灰色的背景线 -->
		<view class="line"></view>

		<!-- 详细介绍 -->
		<view class="details">
			<view class="tit">详情介绍</view>
			<view class="content">
				<rich-text :nodes="list.detailed"></rich-text>
			</view>
		</view>

		<!-- 详情图片 -->
		<view class="details_img">
			<image :src="item" v-for="(item,index) in list.details_img" :key="index"></image>
		</view>

		<!-- 商品导航 -->
		<view class="goodsNav">
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick" @buttonClick="buttonClick" />
		</view>
	</view>
</template>

<script>
	import Vuex from "vuex";
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue';
	export default {
		components: {
			uniGoodsNav
		},
		onLoad() {
			this.getOpenerEventChannel().on('goodsDetail', res => {
				this.list = res.item;
			});
		},
		data() {
			return {
				list: null,

				// 商品导航栏的内容数据
				options: [{
					icon: 'headphones',
					text: '客服'
				}, {
					icon: 'cart',
					text: '购物车',
					info: 0
				}],
				buttonGroup: [{
					text: '加入购物车',
					backgroundColor: '#ff0000',
					color: '#fff'
				}, {
					text: '立即购买',
					backgroundColor: '#ffa200',
					color: '#fff'
				}],
			};
		},
		methods: {
			...Vuex.mapMutations(["addCart"]),
			onClick(e) {
				if (e.content.text === "购物车") {
					uni.switchTab({
						url: "../bottombar/cart/cart",
					})
				};
			},
			async buttonClick(e) {
				if (e.content.text === "加入购物车") {
					this.addCart(this.list);
				};
			}
		}
	}
</script>

<style lang="scss">
	.goodsDetailPage {
		padding: 10rpx 0;
	}

	swiper {
		height: 520rpx;

		>image {
			width: 100%;
			height: 100%;
		}
	}

	.priceName {
		padding: 0 10rpx;

		.price {
			margin-top: 10rpx;
			color: #b50e03;
			font-size: 30rpx;

			>text {
				&:last-of-type {
					color: #ccc;
					font-size: 24rpx;
					margin-left: 15rpx;
					text-decoration: line-through;
				}
			}
		}

		.name {
			font-size: 28rpx;
			line-height: 50rpx;
			padding: 10rpx 0 15rpx 0;
		}
	}

	// 灰色的背景线
	.line {
		width: 750rpx;
		height: 10rpx;
		background-color: #eee;
	}

	// 货号和库存
	.goodsNumberStock {
		padding: 0 10rpx;
		line-height: 60rpx;
	}

	// 详细介绍
	.details {
		.tit {
			font-size: 32rpx;
			padding-left: 10rpx;
			border-bottom: 1rpx solid #eee;
			line-height: 60rpx;
		}

		.content {
			padding: 10rpx;
			font-size: 28rpx;
			color: #333;
		}
	}

	// 详情图片
	.details_img {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 100rpx;
	}

	.goodsNav {
		position: fixed;
		bottom: 0;
		width: 100%;
	}
</style>
